package Game;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;

public class GameField extends JPanel implements MouseListener{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4188873504708875733L;
	public static final int size = 64;
	
	private int x;
	private int y;
	private int xx;
	private int yy;
	private boolean mouseOver;

	public GameField(int x, int y, int xx, int yy) {
		this.x = x;
		this.y = y;
		this.xx = xx;
		this.yy= yy;
		this.mouseOver = false;
		this.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
		this.setOpaque(false);
		this.setMaximumSize(new Dimension(size, size));
		this.setMinimumSize(new Dimension(size, size));
		this.setPreferredSize(new Dimension(size, size));
		this.addMouseListener(this);
	}

	public void mouseClicked(MouseEvent e) {
		Main.click(Player.PlayerID.you, x, y, xx, yy);
	}

	public void mouseEntered(MouseEvent e) {
		if (!mouseOver) {
			mouseOver = true;
			repaint();
		}
	}

	public void mouseExited(MouseEvent e) {
		if (mouseOver) {
			mouseOver = false;
			repaint();
		}
	}

	public void mousePressed(MouseEvent e) {
	}

	public void mouseReleased(MouseEvent e) {
	}
	
	public void paintComponent(java.awt.Graphics g) {
		super.paintComponent(g);
		Player.PlayerID player = Main.getPlayer(x, y, xx, yy);
		if (player != null && Player.getPlayerByID(player).getSign() != null) {
			BufferedImage graphic = Graphics.getGraphic(Player.getPlayerByID(player).getSign().name());
			g.drawImage(graphic, 0, 0, null);
		}
		if (mouseOver) {
			g.setColor(new Color(0x80FFFFFF, true));
			g.fillRect(0, 0, size, size);
		}
	}

}
